//
// Created by xili on 2024/8/13 19:27.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int findMaxK(vector<int> &nums) {
        sort(nums.begin(), nums.end());
        int n = nums.size();
        int l = 0, r = n - 1;
        while (l < r && nums[l] < 0) {
            int diff = nums[l] + nums[r];
            if (diff == 0) {
                return nums[r];
            } else if (diff < 0) {
                l++;
            } else {
                r--;
            }
        }
        return -1;
    }
};